import { BizOrderListEntity } from '../../entity/list';
import { BizOrderListService } from '../../service/list';
import {
  CoolController,
  BaseController,
  CoolUrlTag,
  CoolTag,
  TagTypes,
} from '@cool-midway/core';
import { ALL, Post, Body, Inject } from '@midwayjs/decorator';

/**
 * 预约订单
 */
@CoolUrlTag()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: BizOrderListEntity,
  service: BizOrderListService,
  pageQueryOp: {
    fieldEq: ['id', 'orderNo', 'userId', 'status'],
    keyWordLikeFields: ['orderNo'],
  },
})
export class BizOrderListController extends BaseController {
  @Inject()
  bizOrderListService: BizOrderListService;

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/wxPayNotify', { summary: '微信支付 通知商户url地址' })
  async wxPayNotify(@Body(ALL) params: any) {
    return this.ok(await this.bizOrderListService.wxPayNotify(params));
  }

  @Post('/auditingProof', {
    summary: '结算审核',
  })
  async auditingProof(
    @Body('orderId') orderId: number,
    @Body('targetStatus') targetStatus: number // 审核目标状态
  ) {
    return this.ok(
      await this.bizOrderListService.auditingProof(orderId, targetStatus)
    );
  }

  @Post('/activeCancelOrder', {
    summary: '取消订单',
  })
  async activeCancelOrder(
    @Body('orderNo') orderNo: string,
    @Body('notes') notes: string,
    @Body('orderType') orderType: number
  ) {
    return this.ok(
      await this.bizOrderListService.activeCancelOrder(
        orderNo,
        notes,
        orderType
      )
    );
  }

  @Post('/activeUpdateTOrderStatus', {
    summary: '查询第三方支付订单状态',
  })
  async activeUpdateTOrderStatus(
    @Body('orderNo') orderNo: string,
    @Body('orderType') orderType: number
  ) {
    return this.ok(
      await this.bizOrderListService.activeUpdateTOrderStatus(
        orderNo,
        orderType
      )
    );
  }

  @Post('/sendOrderSMS', {
    summary: '发送订单提示短信',
  })
  async sendOrderSMS(@Body('orderNo') orderNo: string) {
    return this.ok(await this.bizOrderListService.sendOrderSMS(orderNo));
  }
}
